package com.jmgd.cjlx.service.impl;

import com.jmgd.cjlx.constants.MainConstant;
import com.jmgd.cjlx.dao.JmgdMapper;
import com.jmgd.cjlx.service.SendSMSService;
import com.jmgd.cjlx.util.SendSms;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SendSMSImpl implements SendSMSService {
    @Autowired
    JmgdMapper jmgdMapper;

    @Override
    public String sendSMS(String mobile, String balance,String busno) throws Exception{
        String busname = jmgdMapper.selectBusname(busno);
        System.out.println("余额短信提醒发送");
        String templateParas = "[\""+busname+"\",\""+balance+"\"]";
        SendSms.sendSms(mobile, MainConstant.templateId1,templateParas);
        return null;
    }

    @Override
    public String sendNotBalanceSMS(String mobile, String currentbalance, String busno, String balance) throws Exception {
        String busname = jmgdMapper.selectBusname(busno);
        System.out.println("余额不足短信提醒发送");
        String templateParas = "[\""+busname+"\",\""+currentbalance+"\",\""+balance+"\"]";
        SendSms.sendSms(mobile, MainConstant.templateId2,templateParas);
        return null;
    }

    @Override
    public String sendChoujiang(String lotteryid) throws Exception {
        List<Map<String, Object>> choujiangList = jmgdMapper.selectChoujiang(lotteryid);
        for (Map<String, Object> map : choujiangList) {
//            System.out.println(map.get("EMP_NAME").toString());
//            System.out.println(map.get("MOBILE").toString());
//            System.out.println(map.get("LOTTERYNAME").toString());

            String empName = map.get("EMP_NAME").toString();
            String choujiang = map.get("LOTTERYNAME").toString();
            String mobile = map.get("MOBILE").toString();
            String templateParas = "[\""+empName+"\",\""+choujiang+"\"]";
            SendSms.sendSms(mobile, MainConstant.templateId3,templateParas);
        }


        return null;
    }
}
